Skip to content

fix: remove try-catch blocks that swallow exceptions#232

Merged
codebutler merged 2 commits intomasterfrom
fix/remove-swallowed-exceptions
Feb 17, 2026
Merged

fix: remove try-catch blocks that swallow exceptions#232
codebutler merged 2 commits intomasterfrom
fix/remove-swallowed-exceptions

Conversation

@codebutler
Copy link
Owner

Summary

  • En1545 parsers (FixedInteger, FixedHex, Bitmap, Repeat, FixedString): Replace try-catch around bitParser with bounds checking (off + len <= b.size * 8). Root cause was ArrayIndexOutOfBoundsException on truncated card data.
  • Oyster (Transaction, Refill, TravelPass): Replace try-catch with block bounds checking (block < sector.blocks.size). Root cause was potential IndexOutOfBoundsException on partially-read cards.
  • SmartRiderTagRecord: Remove dead try-catch around readASCII() — after isASCII() returns true, readASCII() cannot throw.
  • App.kt: Remove try-catch around sample import so errors bubble up to the user instead of being silently swallowed.
  • ByteUtils.getHexString: Remove dead try-catch — getHexString(b) only iterates bytes and appends hex chars, it cannot throw.

Test plan

  • CI tests pass (allTests)
  • En1545-based transit cards (Calypso/Intercode, Mobib, etc.) still parse correctly with truncated data
  • Oyster card parsing handles partially-read sectors gracefully
  • SmartRider route names display correctly for both ASCII and hex data
  • Sample card import shows errors to the user when import fails

🤖 Generated with Claude Code

Claude and others added 2 commits February 16, 2026 19:06
- Replace deprecated compose.foundation/material3/materialIconsExtended
  with version catalog entries (libs.compose.*)
- Add @OptIn for ExperimentalWasmDsl in app/web and
  ExperimentalKotlinGradlePluginApi in tools/mdst
- Remove unnecessary elvis operators on non-null UnauthorizedException.message
- Remove unnecessary !! on non-null exception messages in DesfireProtocolTest
- Remove redundant type checks (assertTrue(x is T)) where compiler
  already knows the type from generic return types
- Remove unnecessary casts after smart casts from assertTrue contracts
- Remove unnecessary safe calls on non-null receivers
- Clean up unused imports via ktlintFormat

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace exception-swallowing catch blocks with proper root cause fixes:

- En1545 parsers (FixedInteger, FixedHex, Bitmap, Repeat, FixedString):
  Replace try-catch around bitParser with bounds checking
  (off + len <= b.size * 8) before calling bitParser. The root cause
  was ArrayIndexOutOfBoundsException on truncated card data.

- Oyster (Transaction, Refill, TravelPass): Replace try-catch with
  block bounds checking (block < sector.blocks.size). The root cause
  was potential IndexOutOfBoundsException on partially-read cards.

- SmartRiderTagRecord: Remove dead try-catch around readASCII().
  After isASCII() returns true, readASCII() cannot throw.

- App.kt: Remove try-catch around sample import so errors bubble up
  to the user instead of being silently swallowed.

- ByteUtils.getHexString: Remove dead try-catch. getHexString(b)
  only iterates bytes and appends hex chars — it cannot throw.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codebutler codebutler merged commit fa5812e into master Feb 17, 2026
6 checks passed
@codebutler codebutler deleted the fix/remove-swallowed-exceptions branch February 17, 2026 00:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments